package com.tjnmt.togo.utils;

import android.content.Context;
import android.os.PowerManager;
/**
 * 电源状态管理工具类。
 */
public class PowerManagerUtil {
    private static  PowerManager powerManager;
    private static  PowerManager.WakeLock wakeLock;

   /* static {
        powerManager = (PowerManager)ApplicationUtils.getContext().getSystemService(Context.POWER_SERVICE);
        //屏幕和电源关闭,CPU不休眠。
        wakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,"Service Running");
    }*/
    public static void init(Context context){
        powerManager = (PowerManager)context.getSystemService(Context.POWER_SERVICE);
        //屏幕和电源关闭,CPU不休眠。
        wakeLock = powerManager.newWakeLock(PowerManager.FULL_WAKE_LOCK,"Service Running");
    }
    public static void acquireWakeLock(){
        if(wakeLock == null){
            wakeLock.acquire();
        }
    }

    public static void releaseWakeLock() {
        if (wakeLock != null && wakeLock.isHeld()){
            wakeLock.release();
        }
    }
}
